/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.activity.editpart;

import org.eclipse.draw2d.IFigure;
import org.eclipse.uml2.uml.CentralBufferNode;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ElementImport;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.figures.IconFigure;
import com.cea.papyrus.diagram.activity.figure.ObjectNodeFigure;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;
import com.cea.papyrus.diagraminterchange2.di2.Uml1SemanticModelBridge;

/**
 * Controller of a CentralBufferNode
 *
 * @author Gilles Cannenterre
 * @since 26 mars 07
 */
public class CentralBufferNodeEditPart extends ObjectNodeEditPart {

	/**
	 * The constructor.
	 * 
	 * @param modelManager the associated ModelManager
	 * @param graphNode the GraphNode to be managed
	 */
	public CentralBufferNodeEditPart(GraphNode graphNode, ModelManager modelManager) {
		super(graphNode, modelManager);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.editpart.GraphNodeWithSemanticEditPart#getUmlElement()
	 */
	@Override
	public CentralBufferNode getUmlElement() {
		Element e = ((Uml1SemanticModelBridge)getGraphNode().getSemanticModel()).getElement();
		// Case of element import
		if(e instanceof ElementImport){
			return (CentralBufferNode)((ElementImport) e).getImportedElement();
		}
		// This is a simple CentralBufferNode
		return (CentralBufferNode)e;
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.editpart.GraphNodeWithSemanticEditPart#createFigure()
	 */
	@Override
	protected IFigure createFigure() {
		// Force initialization of the manager when figure has changed
		manager = null;
		// Try to get figure from ContainerWithSemanticEditPart
		IFigure fig = super.createFigure();
		if (!(fig instanceof IconFigure)) {
			return new ObjectNodeFigure("centralBuffer");
		}
		// Else
		return fig;				
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.diagram.activity.editpart.ObjectNodeEditPart#refreshVisuals()
	 */
	@Override
	protected void refreshVisuals() {
		super.refreshVisuals();
//		ObjectNodeFigure fig = (ObjectNodeFigure)getFigure();
//		fig.labelState.setText("[sate 1, state 2]");
	}
}
